name: Release

on:
  release:
    types: [published]

env:
  AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
  AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

permissions:
  contents: read

jobs:
  release:
    runs-on: ubuntu-20.04
    steps:
      - uses: actions/checkout@v4
      - uses: ./.github/actions/setup-java
      - name: Clear existing docker image cache
        run: docker image prune -af

      - name: Setup Gradle Build Action
        uses: gradle/actions/setup-gradle@v3

      - name: Run Gradle Build
        run: ./gradlew build --scan --no-daemon -i -x test

      - name: Run Gradle Publish
        run: |
          ./gradlew publish \
            -Pversion="${{github.event.release.tag_name}}" --scan --no-daemon -i
        env:
          OSSRH_USERNAME: ${{secrets.OSSRH_USERNAME}}
          OSSRH_PASSWORD: ${{secrets.OSSRH_PASSWORD}}
